package ysq.xyg.host.controller;

import org.springframework.ui.Model;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.host.model.po.HostCity;
import ysq.xyg.host.model.vo.HostCityVo;
import ysq.xyg.host.service.HostCityService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 房产模块-城市controller层
 *
 * @author shengQiang yu
 * @date 2019-7-1 13:49:33
 */
@RestController
public class HostCityController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(HostCityController.class);
    @Resource
    private HostCityService hostCityService;

    private HostCity hostCity;

    @RequestMapping("/host/*")
    public Model goPage(Model model) {
        return model;
    }
    /**
     * 分页查询
     *
     * @param hostCityVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author shengQiang yu
     * @date 2019-7-1 13:49:33
     */
    @BaseLog(module = "房产模块",className = "城市",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostCity/page",method = RequestMethod.POST)
    public ReturnEntity page(HostCityVo hostCityVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = hostCityService.page(hostCityVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-7-1 13:49:33
     */
    @RequestMapping(value = "/hostCity/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/host/hostCityUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            hostCity = hostCityService.selectByPrimaryKey(id);
            view.addObject("hostCity", hostCity);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author shengQiang yu
     * @date 2019-7-1 13:49:33
     */
    @BaseLog(module = "房产模块",className = "城市",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostCity/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return hostCityService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 添加或修改
     *
     * @param hostCityVo Vo对象
     * @author shengQiang yu
     * @date 2019-7-1 13:49:33
     */
    @BaseLog(module = "房产模块",className = "城市",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/hostCity/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,HostCityVo hostCityVo){
        return hostCityService.addOrUpdate(hostCityVo,acceptCurrentUser(request));
    }
    /**
     * 获取下拉框集合
     *
     * @param code code值
     * @author shengQiang yu
     * @date 2019-4-25 16:49:54
     */
    @RequestMapping(value = "/hostCity/acceptSelect",method = RequestMethod.POST)
    public ReturnEntity acceptSelect(String code){
        return hostCityService.acceptSelect(code);
    }
}